package com.manager.devicemanager.controller;
import com.manager.devicemanager.common.Result;
import com.manager.devicemanager.entity.IcboardRealtime;
import org.springframework.util.StringUtils;
import com.manager.devicemanager.service.IIcboardRealtimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.manager.devicemanager.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpf
 * @since 2025-09-04
 */
@Tag(name = "IcboardRealtimeController", description = " 相关接口")
@RestController
@RequestMapping("/icboardRealtime")
public class IcboardRealtimeController {

    @Autowired
    private IIcboardRealtimeService iIcboardRealtimeService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public Result<IcboardRealtime> save(@Parameter(description = "IcboardRealtime 对象") @RequestBody IcboardRealtime icboardRealtime){
       iIcboardRealtimeService.save(icboardRealtime);
        return Result.success(icboardRealtime);
    }

    @Operation(summary = "按id删除")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@Parameter(description = "记录ID", example = "1") @PathVariable("id") String id){
       iIcboardRealtimeService.removeById(id);
        return Result.success(id);
    }





    @Operation(summary = "条件查询带分页")
    @PostMapping("/page")
    public Result<IPage<IcboardRealtime>> page(@Parameter(description = "查询条件对象") @RequestBody  PageVO<IcboardRealtime> icboardRealtimeQuery){
        int pageNum = icboardRealtimeQuery.getPageNum();
        int pageSize = icboardRealtimeQuery.getPageSize();
        IcboardRealtime icboardRealtime = icboardRealtimeQuery.getCondition();
         QueryWrapper<IcboardRealtime> wrapper =new QueryWrapper<>(icboardRealtime);
        //if (StringUtils.hasText(icboardRealtime.getName())) {
          //  wrapper.like("name", icboardRealtime.getName());
        //}
        IPage<IcboardRealtime> icboardRealtimeList =iIcboardRealtimeService.page(new Page<>(pageNum, pageSize),wrapper );
        return Result.success(icboardRealtimeList);
    }

    @Operation(summary = "条件查询")
    @PostMapping("/list")
    public Result<List<IcboardRealtime>> list(@Parameter(description = "IcboardRealtime 查询条件对象") @RequestBody IcboardRealtime icboardRealtime){
        List<IcboardRealtime> icboardRealtimeList =iIcboardRealtimeService.list(new QueryWrapper<>(icboardRealtime));
        return Result.success(icboardRealtimeList);
    }
}
